home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
F1 Licenseware
/
F1 Licenseware - Volume 1.iso
/
disks
/
089a.dms
/
089a.adf
/
TEXTS
/
CHAPTERS_21-30
/
Chapter28.txt
< prev
next >
Wrap
Text File
|
1992-03-06
|
9KB
|
224 lines
The Absolute Beginners Guide To Amos
-------------------------------------
Chapter Twenty Eight
--------------------
We will now look at another program I wrote for Amoszine a while ago.
The program was just an example of how you can rip Amos ABK pictures out of
an executable file and re-claim them as IFF pictures.
The Ripper uses quite a few new commands I haven't mentioned yet and which,
as usual, will be covered in detail.
The full program is contained in EXAMPLE28.Amos. What I suggest you should
do is to make a test file for the ripper to use. Spack a few pictures into
some memory banks in Amos and compile and save the program as a Workbench
executable. Load up Example28.Amos, Run it, and using the file selector
select your "test file" and see your spacked pics get ripped right back into
IFF picture files. Please do that now before reading on as you may not
know what I am going on about.
I will just discuss the new commands and techniques used in the ripper
program here.
<:-------------------:>
SET BUFFER 250
--------------
As the file the user will want to load is an executable file, it's going
to be quite big so we must set aside a large chunk of memory using the
Set Buffer instruction. SET BUFFER has to be the very first command in your
program (except Rem's) otherwise an error will occur.
See Chapter 16 for a few more details.
Here is the subroutine that loads in the executable file.
'BLoad the file in using the file selector
'-----------------------------------------
_LOADPIC:
F$=Fsel$("*.*","","LOAD EXE")
If Length(10)>0 Then Erase 10
Open In 1,F$ : BL=Lof(1)
Reserve As Data 10,BL
Close 1
Bload F$,10
The first new command we come across is LENGTH , this function returns the
LENGTH in bytes of an Amos memory bank, in this case bank 10. What the
above line is doing is checking to see if bank 10 has anything in it or not.
If it has, then LENGTH will return the value, which will be more than 0 if
the bank has anything in it. If this is the case the bank is cleared using
the ERASE 10 instruction.
If LENGTH returned 0 then the second part of the line is ignored by Amos as
that means the bank is already empty. Why bother checking? Because we are
going to reserve that bank to the size of the incoming file and if you try
to reserve a bank that isn't empty you will get a "Bank already reserved"
error.
RESERVE AS DATA is also an instruction we haven't looked at before.
This simply makes a bank any size we want. In this case we want the bank to
be the size of the incoming file. As the file size can be anything from 60k
upwards we have to look at the file to interrogate it's size. This is done
by using the OPEN IN command. The 1 after OPEN IN is the channel number,
don't worry, the 1 is only for your reference as you can OPEN more than one
channel at a time. F$ is the name of the file selected by the user so
OPEN IN 1,F$ OPENs a channel to look at the file called F$. All this is done
just so we can use the LOF function. LOF stands for Length Of File. In this
program we have assigned the variable BL to equal the Length of the file:
BL=LOF(1), the 1 is the channel number. So now we have the correct info to
Reserve bank 10 to the same length as the incoming file with:
Reserve As Data 10,BL
The 10 is the bank number and BL the length. After using an OPEN IN
instruction you must always CLOSE the channel when you have finished using
it. CLOSE channel number. That's what the CLOSE 1 does.
BLOAD is very similar to other LOAD instruction except that BLOAD will not
check, alter, or interfere with the file in any way. For example, try
loading the same file into the Amos editor. Amos will report that
"This is not an Amos program". F$ as usual, is the file name to load and the
10 is the place we want the file to be loaded to (Bank 10)
'This is where we do all the searching
'-------------------------------------
_SEARCHPICS:
SEARCH$="Pac"
ADR=Hunt(Start(10)+COUNT To Start(10)+Length(10),SEARCH$)
If ADR=0 Then Print "ALL DONE! NO (MORE) PICS FOUND" : Wait 120 : Return
If Peek(ADR+4)=80 and Peek(ADR+5)=105 and Peek(ADR+6)=99
B$="PIC.PAC HEADER FOUND AT"+Str$(ADR)
Print ,B$
COUNT=ADR+100
End If
Return
Search$ is a variable which will hold the text string we are searching for.
In this case the beginning of a spacked memory bank header starts with "Pac"
This will be passed to the HUNT function.
ADR is the variable I have tagged to the HUNT function to hold the result
of the operation this will hold 0 if nothing has been found or the address
of the "P" (in "Pac") in memory. I will explain the PEEK function later.
We now have to tell HUNT exactly where to search for the "Pac" string by
giving a start address and an end address. Start (10) means the first
address of bank 10. The +COUNT bit is used in case we have already
found a picture previously in the same search. If a pic is found and we
re-call this routine it would start back at the beginning and keep finding
the same picture. But if we record the address of the last pic found in the
COUNT variable and add 100 to it then the search will resume just past the
last found pic header. So if in the first pass HUNT found a picture at
address 50000 then when Amos returned to continue searching for the next
picture the search would start at START(10)+50100. If it started at 50000
it would still catch the last picture found so we add 100 bytes to make sure
it skips it.
'Restore the picture to be a true Amos ABK pic
'---------------------------------------------
_HEADER:
'
'poke ABk at new start of bank
Poke ADR-12,65
Poke ADR-11,109
Poke ADR-10,66
Poke ADR-9,107
'
'restore some data discarded by compiler
Poke ADR-8,0
Poke ADR-7,$A
Poke ADR-6,0
Poke ADR-5,0
Poke ADR-4,$80
Poke ADR-3,0
Poke ADR-2,$1C
Poke ADR-1,$32
'Guess length for now
Bsave "ram:pic.abk",ADR-12 To ADR+72000
Gosub _VIEWPIC
Gosub _SAVEPIC
Return
The POKE instruction allows you to change the contents of memory. What we
are doing in the above routine is POKEing what should be the correct
information to the ABK header of the picture. The form of the POKE command
works like this:
POKE Address,Value
Where the address is the memory location you want to change and the value is
the new value you wish to change it to. POKE is simple to use but there is
a lot more to it, you can't go poking anything anywhere or you will crash
your program.
You may have noticed a $ as the value for some of the POKEs, that is a sign
meaning that the following number is in Hexadecimal notation. We touched on
Hex briefly in an earlier chapter. Also see the ASCII codes chart if you are
interested in this part of the program. PEEK was used earlier in this
program to read rather than write to an address in memory. PEEK is the
direct opposite to POKE. PEEK is used in the search part of this program to
look for the string "Pac" byte by byte.
After all that POKEing now we can actually "Cut out" the part of memory that
we think is a spacked picture. The problem is knowing the length we need to
cut out. When the Compiler does it's job it erases this important
information so we have only one option and that is to cut out a huge lump.
I decided on 72000 bytes (around 71K) as it's extremely unlikely that a
spacked pic will be that large, the average spacked pic seems to be around
15K so if you are short on memory try lowering this figure.
As the aim of the program is to get the original IFF image in it's correct
size we are far from finished. We save the pic to Ram: for temporary use.
As we are using the BSAVE instruction (See BLOAD) we have to tell Amos the
start address and the length. We know both of these figures. The Start
address will be ADR-12 (-12 bytes to include the new POKEs we have entered
to re-create the original header) The end address will be ADR+72000
(The 72000 is a figure I just plucked out of the air)
OK, so far we have loaded an executable file, found what we hope is a
spacked picture file (ABK) and have cut a copy of it out of memory and saved
it to the Ram Disk.
Now let the user view the picture on screen.
'Display picture if any found
'-----------------------------
_VIEWPIC:
Load "ram:pic.abk",11
Unpack 11 To 0
Wait 25
While Mouse Key=0 : Wend
Return
First we load the Abk file as if it were a normal Abk spacked picture file,
which it is, now that we have modified it! We load it into bank 11.
Then UNPACK it to Screen 0 in the usual way and wait for a mouse click.
'Let user save if
'-----------------
_SAVEPIC:
F$=Fsel$("*.*","","SAVE IFF")
Save Iff F$,0
Return
Now this is the crafty part, we let the user save the SCREEN out as a normal
IFF picture file. Amos saves a copy of the screen and leaves all the
extra wastage behind. So what was a 71K ABK file is now something like the
original 20K IFF file which can now be treated as a normal picture.
After saving, the program then continues searching for more pics until the
end of the bank is reached.
Remember, if the executable file has be crunched or squashed in any way the
ripper will not be able to identify the pic's in it. Also, remember not all
Amos programs contain Spacked memory banks.
End of Chapter Twenty Eight
^^^^^^^^^^^^^^^^^^^^^^^^^^^